<?php
      # 两种登陆模式 : 1. 正常的账号密码登陆;
      #               2. cookie 的免登陆;

      header("content-type:text/json;charset=utf8;");
      header("Access-Control-Allow-Origin:http://localhost:3000");

      // 如果不传递对应的参数,会报错;
      // 有办法消除get的报错;
      $usr = @$_GET["username"];
      $pwd = @$_GET["password"]; 
      
      $con = mysql_connect("localhost","root","root");
      if(!$con){
            die("数据库连接失败".mysql_error());
      }
      mysql_select_db("zbird",$con);

      #判断一下现在的用户名是否存在于数据库之中;
      $sql_select = "SELECT `password`,`id` FROM `user_table` WHERE `username`='$usr'";
      
      $select_res = mysql_query($sql_select);
      $select_res = mysql_fetch_array($select_res);

      if(!$select_res){
            $res_succ = array("state" => "error","msg" => "用户名不存在");
            die (json_encode($res_succ));
      }
     
      if($select_res["password"] == $pwd){

            # 种下cookie => 
            // $cookie_array = array("username" => $usr , "password" => md5($pwd) , "id" => $select_res["id"]);

            // setcookie("USRID",json_encode($cookie_array),time() + 3600 * 24 * 5 , "/");

            $res_succ = array("state" => "success");
            die(json_encode($res_succ));
      }

      $res_succ = array("state" => "error","msg" => "用户名和密码不符");
      echo (json_encode($res_succ));

      mysql_close($con);
?>